package com.InfinityRun;

import java.util.ArrayList;
import java.util.List;

import Objects.GameObject;
import Objects.Obstacle;
import Objects.ObstacleManager;
import Objects.Player;
import Objects.Vector2;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.media.MediaPlayer;
import android.util.Log;
import android.view.MotionEvent;

public class GameScene extends Scene
{
	Player player;
	ObstacleManager obj;
	static GameScene instance = null;
	boolean collisionWithObstacle;
	Vector2 screen;
	Score score;
	
	public GameScene(int screenW, int screenH)
	{
		player = new Player(Assets.player.getWidth(),Assets.player.getHeight(), Assets.player);
		obj = new ObstacleManager();
		this.sound = Assets.gameSound;
		this.sound.start();
		screen = new Vector2(screenW,screenH);
		score = new Score();
	}
	
	@Override
	public void Draw(Canvas c) 
	{
		c.drawRGB(0, 0, 0);
		player.Draw(c);
		obj.draw(c);
		score.draw(c);
	}

	@Override
	public void GetInput(MotionEvent ev)
	{
		if(ev.getAction() == MotionEvent.ACTION_DOWN)
		{
			if(ev.getX() < screen.x * 0.5f)
			{
				player.move("left");
			}
			
			else if(ev.getX() >= screen.x * 0.5f)
			{
				player.move("right");
			}
		}
		
		else if(ev.getAction() == MotionEvent.ACTION_UP)
		{
			player.stopMove();
		}

	}

	@Override
	public void Update(float deltaTime) 
	{
		player.Update(deltaTime);
		obj.update(deltaTime);	
		score.update(deltaTime);
		
		if(score.count >  300)
		{
			MainGame.GoToEscape(true);
		}
		
		for(Obstacle ob : obj.obs)
		{
			if(player.Collision(ob))
			{
				this.sound.pause();
				SceneManager.getInstance().ChangeScene(3);
			}
		}
	}

	@Override
	public void OnPause()
	{
		this.sound.pause();
	}

	@Override
	public void OnResume() 
	{
		this.sound.start();
	}
}
